package com.mew.slots.core.game.hjtg.room;

import cn.hutool.core.util.RandomUtil;
import com.mew.common.util.GameUtil;
import com.mew.slots.core.common.game.BaseRoom;
import com.mew.slots.core.common.utils.SlotsGameUtil;
import com.mew.slots.core.game.hjtg.bo.HjtgPlayMsgs;

import java.util.ArrayList;

public class HjtgRoom extends BaseRoom {
    private final int itemWes[] = new int[]{20000,15000,5000,400,40,20,2,1};
    //选项 int[类型][数值]    类型 1 rate 2 free 3jp
    private final int[][] items = new int[][]{
            {1,1},
            {1,2},
            {1,3},
            {2,10},
            {3,1},
            {3,2},
            {3,3},
            {3,4}
    };
    int rc;
    public HjtgRoom(int rc){
        this.rc = rc;
        res = new HjtgPlayMsgs();
        row = 3;
        col = 5;
        _WILD = 16;
        spes = new ArrayList<Integer>(){};
        //无法描述
        rate = new int[][]{
                {0, 0,  5, 15, 50},      //10            0
                {0, 0,  5, 15, 50},      //J             1
                {0, 0,  5, 15, 50},      //Q             2
                {0, 0,  5, 15, 50},      //K             3
                {0, 0,  5, 15, 50},      //A             4

                {0, 0, 10, 25, 100},      //方块           5
                {0, 0, 10, 25, 100},      //梅花           6
                {0, 0, 10, 25, 100},      //红桃           7
                {0, 0, 10, 25, 100},      //黑桃           8

                {0, 0, 10, 30, 150},      //绿油油 可能是玉   9
                {0, 0, 10, 30, 150},      //美酒            10
                {0, 0, 10, 30, 150},      //戒指            11

                {0, 0, 15, 50, 300},      //汽车           12
                {0, 0, 15, 50, 300},      //游轮           13

                {0, 5, 30, 100,500},      //汽车           14
                {0, 5, 30, 100,500},      //游轮           15

                {0, 0,  0,   0,  0},      //WILD           16
        };
        alllines=new int[][]{
                {5,6,7,8,9},
                {0,1,2,3,4},
                {10,11,12,13,14},
                {0,6,12,8,4},
                {10,6,2,8,14},
                {5,1,7,13,9},
                {5,11,7,3,9},
                {0,1,7,13,14},
                {10,11,7,3,4},
                {0,6,2,8,4},
                {10,6,12,8,14},
                {5,1,2,3,9},
                {5,11,12,13,9},
                {0,6,7,8,4},
                {10,6,7,8,14},
                {5,6,2,8,9},
                {5,6,12,8,9},
                {5,1,7,3,9},
                {5,11,7,13,9},
                {0,1,2,8,14},
                {10,11,12,8,4},
                {0,6,12,13,14},
                {10,6,2,3,4},
                {5,6,7,3,14},
                {5,6,7,13,4},
                {0,6,7,8,14},
                {10,6,7,8,4},
                {10,11,7,3,9},
                {0,1,7,13,9},
                {10,6,12,13,14},
                {0,6,2,3,4},
                {0,6,12,8,9},
                {10,6,2,8,9},
                {5,1,7,3,4},
                {5,11,7,13,14},
                {0,6,7,8,9},
                {10,6,7,8,9},
                {5,1,2,3,4},
                {5,11,12,13,14},
                {5,6,7,8,4},
                {5,6,7,8,14},
                {0,1,7,3,4},
                {10,11,7,13,14},
                {0,1,2,8,4},
                {10,11,12,8,14},
                {5,6,2,3,4},
                {5,6,12,13,14},
                {0,1,7,8,4},
                {10,11,7,8,14},
                {10,6,2,8,4}
        };
    }
    @Override
    public void getLinesXml(){
        if (controlType > 0){
            endSlots = control();
        } else {
            endSlots = rollerXml.getLineInts(free?1:0,rollerID);
        }
        res.endSlots=endSlots;
        if(free){
            replaceFreeIcon();
        }
    }

    private void replaceFreeIcon(){
        for (int r = 0; r < row; r++) {
            endSlots[r*5+rc] = _WILD;
        }
        ((HjtgPlayMsgs)res).setRc(rc);
    }

    @Override
    public void freeBouns(){
        if(!free) {
            int index = controlSpecial();
            int[] item = items[index];
            switch (item[0]) {
                case 1:
                    res.setMultiple(res.getMultiple() * item[1]);
                    break;
                case 2:
                    res.setFree((byte) 1);
                    res.setFreeNumber(item[1]);
                    break;
                case 3:
                    res.setJp(item[1]);
                    break;
            }
            ((HjtgPlayMsgs)res).setIndex(index);
        }
    }

    @Override
    public int[] control(){
        switch (controlType) {
            case 1:
                return bigwin();
            default:
                return SlotsGameUtil.getEndSlots(16);
        }
    }

    private int controlSpecial(){
        if(controlType == 2){
            return 3;
        }
        if(controlType == 4){
            return RandomUtil.randomInt(4,8);
        }
        return  GameUtil.weights(itemWes);
    }
}
